#include <atomic>
#include <iostream>
#include <thread>
#include <vector>

std::atomic<int> x(0);

void write_x() {
    x.store(1, std::memory_order_relaxed);  // 对x的写入，不需要与其他线程同步
}

void read_x_and_print() {
    // 循环直到x变为1，但由于内存顺序是relaxed，这个变化可能无法立即在其他线程中观察到
    while (true) {
        int current_x = x.load(std::memory_order_relaxed);
        if (current_x == 1) {
            std::cout << "x was set to 1" << std::endl;
            break;
        }
    }
}

int main() {
    std::thread writer(write_x);
    std::thread reader(read_x_and_print);

    writer.join();
    reader.join();

    return 0;
}